﻿// Test_Protocol.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
using namespace std;
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_Lib/NetEngine_BaseLib/BaseLib_Define.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine/NetEngine_Protocol/Protocol_Define.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine/NetEngine_Protocol/Protocol_Define.h"

#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"../../../../NetEngine_Windows/NetEngine_SourceCode/Debug/NetEngine_Protocol.lib")

void __stdcall XEngine_Protocol_Callback_Trace(LPCTSTR lpszSource, LPCTSTR lpszDestAddr, LPCTSTR lpszRecvAddr, int nTTL, NETENGINE_VALTIME st_VALTime, LPVOID lParam)
{
	printf("Src:%s Dst:%s Rcv:%s TTL:%d Time:%lld.%llu\n", lpszSource, lpszDestAddr, lpszRecvAddr, nTTL, st_VALTime.tv_sec, st_VALTime.tv_usec);
}
int Protocol_TestPing()
{
	LPCTSTR lpszSourceAddr = _T("192.168.1.2");
	LPCTSTR lpszDestAddr = _T("129.211.96.206");
	NETENGINE_VALTIME st_VALTime;

	memset(&st_VALTime, '\0', sizeof(NETENGINE_VALTIME));

	if (!Protocol_Icmp_Ping(lpszSourceAddr, lpszDestAddr, &st_VALTime))
	{
		printf("errno\n");
		return 0;
	}

	printf("%lld %llu\n", st_VALTime.tv_sec, st_VALTime.tv_usec);

	return 0;
}
int Protocol_TestTrace()
{
	LPCTSTR lpszSourceAddr = _T("192.168.1.2");
	LPCTSTR lpszDestAddr = _T("129.211.96.206");

	if (!Protocol_Icmp_Traceroute(lpszSourceAddr, lpszDestAddr, XEngine_Protocol_Callback_Trace))
	{
		printf("errno\n");
		return 0;
	}

	return 0;
}
int main()
{
    WSADATA st_WSAData;
    WSAStartup(MAKEWORD(2, 2), &st_WSAData);

	//Protocol_TestPing();
	Protocol_TestTrace();

    WSACleanup();
    return 0;
}